package com.hudongwx.sadpw.fragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hudongwx.sadpw.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.xutils.x;

/**
 * Author:Literary
 * DateTime:16-12-14 下午2:18
 */
public class MyListViewAdapter extends BaseAdapter {
    JSONArray jsonArray;
    Context context;

    public MyListViewAdapter(JSONArray jsonArray, Context context) {
        this.jsonArray = jsonArray;
        this.context = context;
    }

    @Override
    public int getCount() {
        return jsonArray.length();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyListViewHolder1 myViewHolder;
        if (null==convertView){
          myViewHolder=new MyListViewHolder1();
           convertView= LayoutInflater.from(context).inflate(R.layout.item_home2,null);
            myViewHolder.imageView= (ImageView) convertView.findViewById(R.id.hotpoint_iv_1);
            myViewHolder.textView1= (TextView) convertView.findViewById(R.id.hotpoint_tv_1);
            myViewHolder.textView2= (TextView) convertView.findViewById(R.id.hotpoint_tv_2);
            convertView.setTag(myViewHolder);
        }else {
             myViewHolder= (MyListViewHolder1) convertView.getTag();
        }
        try {
            myViewHolder.textView1.setText(jsonArray.getJSONObject(position).getString("Title"));
            myViewHolder.textView2.setText(jsonArray.getJSONObject(position).getString("BoardName"));
            x.image().bind(myViewHolder.imageView,jsonArray.getJSONObject(position).getString("CoverImg"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return convertView;

    }
    class MyListViewHolder1{
        TextView textView1,textView2;
        ImageView imageView;
    }
}
